package com.alvis.media.controller.admin;

import com.alvis.media.base.BaseApiController;
import com.alvis.media.base.RestResponse;
import com.alvis.media.domain.User;
import com.alvis.media.service.UserService;
import com.alvis.media.service.VideoInfoService;
import com.alvis.media.viewmodel.admin.dashboard.IndexVM;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;


/**
 * 前后端对接：JSON/XML
 * 三层：
 * Controller/Handler/Action层  表现层  负责和用户交互 && 调用Service层
 * Service层                    业务层   && 调用DAO层
 * DAO层/Repository/Mapper      持久化层/数据访问层   调用持久化设备（DB、文件等）
 * ----------常见的包-----------------
 * domain/pojo/entity 实体类
 * utils              工具类 static的方法
 * exception          自定义异常
 * listener           监听器
 */
@RestController("AdminDashboardController") // 返回JSON数据
@RequestMapping(value = "/api/admin/dashboard")
@AllArgsConstructor
public class DashboardController extends BaseApiController
{
    // DI/IoC
    @Autowired
    private UserService userService;

    // DI/IoC
    @Autowired
    private VideoInfoService videoInfoService;

    @RequestMapping(value = "/index", method = RequestMethod.POST)
    public RestResponse<IndexVM> Index()
    {
        IndexVM vm = new IndexVM();
        Integer monthUserTotalCount = userService.queryUserCount(new User());
        vm.setNewUserCount(monthUserTotalCount);

        vm.setNewVideoCount(50);

        vm.setDoPlayVideoCount(50);

        vm.setHotVideoCount("我和我的妈妈");

        // 用户活跃度数据
        List<Integer> userActiveCount = new ArrayList<Integer>();
        userActiveCount.add(30);
        userActiveCount.add(10);
        userActiveCount.add(5);
        userActiveCount.add(1);
        userActiveCount.add(7);
        userActiveCount.add(12);
        userActiveCount.add(15);
        vm.setMothDayUserActionValue(userActiveCount);
        
        // 视频播放次数数据
        List<Integer> videoPlayCount = new ArrayList<Integer>();
        videoPlayCount.add(25);
        videoPlayCount.add(22);
        videoPlayCount.add(18);
        videoPlayCount.add(15);
        videoPlayCount.add(10);
        videoPlayCount.add(8);
        videoPlayCount.add(5);
        videoPlayCount.add(3);
        videoPlayCount.add(1);
        videoPlayCount.add(2);
        videoPlayCount.add(4);
        videoPlayCount.add(6);
        vm.setMothDayVideoPlayValue(videoPlayCount);
        
        // 设置日期文本标签
        List<String> dayLabels = new ArrayList<String>();
        dayLabels.add("1日");
        dayLabels.add("2日");
        dayLabels.add("3日");
        dayLabels.add("4日");
        dayLabels.add("5日");
        dayLabels.add("6日");
        dayLabels.add("7日");
        dayLabels.add("8日");
        dayLabels.add("9日");
        dayLabels.add("10日");
        dayLabels.add("11日");
        dayLabels.add("12日");
        vm.setMothDayText(dayLabels);

        return RestResponse.ok(vm);
    }
}
